package com.example.demo.mapper;

import com.example.demo.model.OrderItem;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface OrderItemMapper {

    @Select("SELECT * FROM order_item WHERE item_id = #{id}")
    OrderItem findById(Integer id);

    @Select("SELECT * FROM order_item WHERE order_id = #{orderId}")
    List<OrderItem> findByOrderId(String orderId);

    @Insert("INSERT INTO order_item(order_id, dish_id, quantity, unit_price, subtotal) " +
            "VALUES(#{orderId}, #{dishId}, #{quantity}, #{unitPrice}, #{subtotal})")
    @Options(useGeneratedKeys = true, keyProperty = "itemId")
    int insert(OrderItem orderItem);

    @Delete("DELETE FROM order_item WHERE item_id=#{id}")
    int delete(Integer id);

    @Delete("DELETE FROM order_item WHERE order_id=#{orderId}")
    int deleteByOrderId(String orderId);
}